// care_worker_lease_rcord.js
var app = getApp()
//常量数据配置
var ConstantData = require('../../../../common/constant_data.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone:'',  
    leseList:[],
    pageNum: 1,
    numPerPage: 10
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var phone = options.phone
     var key = options.key
     this.setData({
       phone:phone,
       key:key
     })
     this.getApgeLeaseRecord()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.loading && !that.data.loadingComplete) {
      that.setData({
        pageNum: that.data.pageNum + 1,  //每次触发上拉事件，把searchPageNum+1  
      });
      that.getApgeLeaseRecord();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  /**
   * 查看护工的租赁记录
   */
  getApgeLeaseRecord: function () {
    var that = this
    var phone = this.data.phone

    app.executeRequest(function (header) {

      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/time_card_patient/lease_rcord',
        header: header,
        data: {
          key: that.data.key,
          phone: phone,
          numPerPage: that.data.numPerPage,
          pageNum: that.data.pageNum
        },
        success: function (res) {
          var result = res.data
          var rst = result.result
          if (rst == 0) {
            //获取成功
            var oldList = that.data.leseList
            var newList = oldList.concat(res.data.data.data)
            if (res.data.data.pageNum * that.data.numPerPage >= res.data.data.total) {
              that.setData({
                loading: false,
                loadingComplete: true,
                leseList: newList
              });
            } else {
              that.setData({
                loading: true,
                loadingComplete: false,
                leseList: newList
              });
            }
          } else {
            wx.showToast({
              title: result.description,
            })
          }
        },
        fail: function () {
          wx.showToast({
            title: '稍后重试',
          })
        }
      })

    })
    
  }
})